import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

// 固定路由
const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/register/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

]
// 动态路由
export const asyncRouterMap = [
  // 数据统计
  {
    path: '/dataStatistics',
    component: Layout,
    meta: { title: "", icon: "el-icon-s-data", children: ["/dataStatistics"] },
    children: [
      {
        path: '/dataStatistics',
        name: 'DataStatistics',
        component: () => import('@/views/dataStatistics/index'),
        meta: { title: '数据统计', icon: 'el-icon-s-data' }
      }]
  },
  // 用户管理
  {
    path: '/user',
    component: Layout,
    meta: { title: "", icon: "el-icon-user-solid", children: ["/user"] },
    children: [
      {
        path: '/user',
        name: 'User',
        component: () => import('@/views/user/index'),
        meta: { title: '用户', icon: 'el-icon-user-solid' }
      }
    ]
  },
  // 管理员管理
  {
    path: '/admin',
    redirect: '/admin',
    component: Layout,
    meta: { title: "", icon: "el-icon-user-solid", children: ["/admin"] },
    children: [
      {
        path: '/admin',
        name: 'Admin',
        component: () => import('@/views/admin/index'),
        meta: { title: '门店管理员', icon: 'el-icon-user' }
      },
    ]
  },
  // 申请管理
  {
    path: '/applyFor',
    component: Layout,
    redirect: '/applyFor/table',
    name: 'ApplyFor',
    meta: { title: '申请处理', icon: 'el-icon-document', children: ["/shopApply", "/shopAdmin"] },
    children: [
      {
        path: '/shopApply',
        name: 'ShopApply',
        name: 'informationw',
        component: () => import('@/views/shopApply/index'),
        meta: { title: '门店申请', icon: 'el-icon-s-shop' }
      },
      { //需要跳转的页面，
        path: '/mess',
        name: 'information',
        component: () => import('@/views/shopApply/mess'),
        meta: { title: '门店申请详情', noCache: true, activeMenu: '@/views/shopApply/mess' },
        hidden: true   //是否显示在菜单
      },
      {
        path: '/shopAdmin',
        name: 'ShopAdmin',
        name: 'informationa',
        component: () => import('@/views/shopAdmin/index'),
        meta: { title: '门店管理员申请', icon: 'el-icon-user-solid' }
      },
      { //需要跳转的页面，
        path: '/message',
        name: 'informations',
        component: () => import('@/views/shopAdmin/message'),
        meta: { title: '门店管理员申请详情', noCache: true, activeMenu: '@/views/shopAdmin/message' },
        hidden: true   //是否显示在菜单
      },
    ]
  },
  // 门店管理
  {
    path: '/shopDoor',
    component: Layout,
    meta: { title: "", icon: "el-icon-user-solid", children: ["/shopDoor", "/shopDoor/shopDoorDetail/:id"] },
    children: [
      {
        path: '/shopDoor',
        name: 'ShopDoor',
        component: () => import('@/views/shopDoor/index'),
        meta: { title: '门店管理', icon: 'el-icon-office-building', noCache: true, activeMenu: '@/views/shopDoor/index', showZj: false },

      },
      {
        path: '/shopDoorDetail/:id',
        name: 'ShopDoorDetail',
        component: () => import('@/views/shopDoor/shopDoorDetail'),
        meta: {
          title: '详情', noCache: true, activeMenu: '@/views/shopDoor/shopDoorDetail'
        },
        hidden: true
      },
    ]
  },
  // 商品管理
  {
    path: '/commodity',
    meta: { title: "", icon: "el-icon-user-solid", children: ["/commodity", "/commodity/commoditydetail/:id"] },
    component: Layout,
    children: [
      {
        path: '/commodity',
        name: 'Commodity',
        component: () => import('@/views/commodity/index'),
        meta: { title: '商品管理', icon: 'el-icon-shopping-bag-2', showZj: false },
      },
      {
        path: '/commoditydetail/:id',
        name: 'Commoditydetail',
        component: () => import('@/views/commodity/commoditydetail'),
        meta: {
          title: '详情', noCache: true, activeMenu: '@/views/commodity/commoditydetail'
        },
        hidden: true
      },
    ]
  },
  // 申请中
  {
    path: '/applying',
    component: Layout,
    meta: { title: "", icon: "el-icon-user-solid", children: ["/applying"] },
    children: [
      {
        path: '/applying',
        name: 'Applying',
        component: () => import('@/views/applying/index'),
        meta: { title: '申请中', icon: 'form' }
      }
    ]
  },
  //服务管理
  {
    path: '/service',
    component: Layout,
    meta: { title: "", icon: "el-icon-user-solid", children: ["/service"] },
    children: [
      {
        path: '/service',
        name: 'Service',
        component: () => import('@/views/service/index'),
        meta: { title: '服务管理', icon: 'el-icon-collection-tag' }
      }
    ]
  },
  // 订单管理
  {
    path: '/orderManage',
    component: Layout,
    redirect: '/orderManage/table',
    name: 'OrderManage',
    meta: { title: '订单管理', icon: 'el-icon-s-order', children: ['/goodsOrder', '/serviceOrder'] },
    children: [
      {
        path: '/goodsOrder',
        name: 'GoodsOrder',
        component: () => import('@/views/goodsOrder/index'),
        meta: { title: '商品订单', icon: 'el-icon-present' }
      },
      {
        path: '/serviceOrder',
        name: 'ServiceOrder',
        component: () => import('@/views/serviceOrder/index'),
        meta: { title: '服务订单', icon: 'el-icon-s-custom' }
      }
    ]
  },

  // // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/login', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}


export default router;